import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'

// 表单校验
export const rules = reactive({
  name: [required],
  dataAllowanceMb: [required],
  validityPeriodDays: [required],
  country: [required],
  type: [required]
})

// CrudSchema https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
  {
    label: '主键',
    field: 'id',
    isSearch: true,
    isForm: false
  },
  {
    label: '名称',
    field: 'name',
    isSearch: true
  },
  {
    label: '流量大小（M）',
    field: 'dataAllowanceMb',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '有效期',
    field: 'validityPeriodDays',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: '国家',
    field: 'country',
    isSearch: true
  },
  {
    label: '描述',
    field: 'description',
    form: {
      component: 'Editor',
      componentProps: {
        valueHtml: '',
        height: 200
      }
    }
  },
  {
    label: '创建时间',
    field: 'createTime',
    formatter: dateFormatter,
    isForm: false
  },
  {
    label: '类型',
    field: 'type',
    isSearch: true,
    form: {
      component: 'SelectV2'
    }
  },
  {
    label: 'Package',
    field: 'packageInfo',
    isTable: false
  },
  {
    label: '操作',
    field: 'action',
    isForm: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
